#define _LCD_MODULE_
#include "osObjects.h"
#include "gd32f20x.h"
#include "gd32f20x_gpio.h"
#include "gd32f20x_rcc.h"
#include "gd32f20x_tldi.h"
#include "lcdctr.h"
#include "pincfg.h"
#include "picture.h"
#include "gd32f20cl_eval_lcd.h"

TLDI_Layer_InitPara TLDI_Layer_InitStruct;

/*****************************************************************************//*!
*
* @brief   lcd task.
*     
* @param   none
*
* @return  none
*
* @ Pass/ Fail criteria: none
*****************************************************************************/
void LcdCtrTask(void * pPar)
{
    OS_ERR      os_err;
    
    LcdInit();
    
    for(;;)
    {
        OSTimeDly(10, OS_OPT_TIME_PERIODIC, &os_err);
        LCD_layer2Display();
    }
}


/*****************************************************************************//*!
*
* @brief   led control init.
*     
* @param   none
*
* @return  none
*
* @ Pass/ Fail criteria: none
*****************************************************************************/
void LcdInit(void)
{
    LCD_Init();
    LCD_LayerInit();
    TLDI_Layer_Enable(TLDI_Layer1, ENABLE);
    TLDI_ReloadConfig(TLDI_RELOADLAYERTYPE_RQR);
    TLDI_Enable(ENABLE);
}

/*****************************************************************************//*!
*
* @brief   lcd layer2 control.
*     
* @param   none
*
* @return  none
*
* @ Pass/ Fail criteria: none
*****************************************************************************/
void LCD_layer2Display(void)
{
    OS_ERR      os_err;
    
    TLDI_Layer_InitStruct.Layer_FrameBufferStartAddress = (uint32_t)&gImage_0;      
    LCD_LayerInit();
    TLDI_Layer_Enable(TLDI_Layer2, ENABLE);
    TLDI_ReloadConfig(TLDI_RELOADLAYERTYPE_RQR);
    TLDI_Enable(ENABLE);

    OSTimeDly(200, OS_OPT_TIME_PERIODIC, &os_err);
    TLDI_Layer_InitStruct.Layer_FrameBufferStartAddress = (uint32_t)&gImage_1;      
    LCD_LayerInit();
    TLDI_Layer_Enable(TLDI_Layer2, ENABLE);
    TLDI_ReloadConfig(TLDI_RELOADLAYERTYPE_RQR);
    TLDI_Enable(ENABLE);

    OSTimeDly(160, OS_OPT_TIME_PERIODIC, &os_err);

    TLDI_Layer_InitStruct.Layer_FrameBufferStartAddress = (uint32_t)&gImage_2;      
    LCD_LayerInit();
    TLDI_Layer_Enable(TLDI_Layer2, ENABLE);
    TLDI_ReloadConfig(TLDI_RELOADLAYERTYPE_RQR);
    TLDI_Enable(ENABLE);

    OSTimeDly(120, OS_OPT_TIME_PERIODIC, &os_err);

    TLDI_Layer_InitStruct.Layer_FrameBufferStartAddress = (uint32_t)&gImage_3;      
    LCD_LayerInit();
    TLDI_Layer_Enable(TLDI_Layer2, ENABLE);
    TLDI_ReloadConfig(TLDI_RELOADLAYERTYPE_RQR);
    TLDI_Enable(ENABLE);

    OSTimeDly(80, OS_OPT_TIME_PERIODIC, &os_err);

    TLDI_Layer_InitStruct.Layer_FrameBufferStartAddress = (uint32_t)&gImage_4;      
    LCD_LayerInit();
    TLDI_Layer_Enable(TLDI_Layer2, ENABLE);
    TLDI_ReloadConfig(TLDI_RELOADLAYERTYPE_RQR);
    TLDI_Enable(ENABLE);

    OSTimeDly(100, OS_OPT_TIME_PERIODIC, &os_err);

    TLDI_Layer_InitStruct.Layer_FrameBufferStartAddress = (uint32_t)&gImage_5;      
    LCD_LayerInit();
    TLDI_Layer_Enable(TLDI_Layer2, ENABLE);
    TLDI_ReloadConfig(TLDI_RELOADLAYERTYPE_RQR);
    TLDI_Enable(ENABLE);

    OSTimeDly(140, OS_OPT_TIME_PERIODIC, &os_err);
     
    TLDI_Layer_InitStruct.Layer_FrameBufferStartAddress = (uint32_t)&gImage_6;      
    LCD_LayerInit();
    TLDI_Layer_Enable(TLDI_Layer2, ENABLE);
    TLDI_ReloadConfig(TLDI_RELOADLAYERTYPE_RQR);
    TLDI_Enable(ENABLE);

    OSTimeDly(180, OS_OPT_TIME_PERIODIC, &os_err);
      
    TLDI_Layer_InitStruct.Layer_FrameBufferStartAddress = (uint32_t)&gImage_7;      
    LCD_LayerInit();
    TLDI_Layer_Enable(TLDI_Layer2, ENABLE);
    TLDI_ReloadConfig(TLDI_RELOADLAYERTYPE_RQR);
    TLDI_Enable(ENABLE);  
    OSTimeDly(200, OS_OPT_TIME_PERIODIC, &os_err);  
}
